﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.PlanningManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.PlanningManagement.ProductionPlanningVMs
{
    public partial class ProductionPlanningListVM : BasePagedListVM<ProductionPlanning_View, ProductionPlanningSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProductionPlanning_View>> InitGridHeader()
        {
            return new List<GridColumn<ProductionPlanning_View>>{
                
                this.MakeGridHeader(x => x.ProductionPlanning_Wo).SetTitle(@Localizer["Page.工单号"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_Sort).SetTitle(@Localizer["Page.排序"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_LineId).SetTitle(@Localizer["Page.产线"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_LineCode).SetTitle(@Localizer["Page.产线编码"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_ShiftId).SetTitle(@Localizer["Page.班次"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_ShiftCode).SetTitle(@Localizer["Page.班次代号"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_ProductCode).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_PlanStartTime).SetTitle(@Localizer["Page.计划开始时间"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_PlanEndTime).SetTitle(@Localizer["Page.计划结束时间"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_PlanQty).SetTitle(@Localizer["Page.计划数量"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_PlanStatus).SetTitle(@Localizer["Page.计划状态"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProductionPlanning_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProductionPlanning_View> GetSearchQuery()
        {
            var query = DC.Set<ProductionPlanning>()
                
                .CheckContain(Searcher.Wo, x=>x.Wo)
                .CheckEqual(Searcher.Sort, x=>x.Sort)
                .CheckEqual(Searcher.LineId, x=>x.LineId)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckEqual(Searcher.ShiftId, x=>x.ShiftId)
                .CheckContain(Searcher.ShiftCode, x=>x.ShiftCode)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductCode, x=>x.ProductCode)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckBetween(Searcher.PlanStartTime?.GetStartTime(), Searcher.PlanStartTime?.GetEndTime(), x => x.PlanStartTime, includeMax: false)
                .CheckBetween(Searcher.PlanEndTime?.GetStartTime(), Searcher.PlanEndTime?.GetEndTime(), x => x.PlanEndTime, includeMax: false)
                .CheckEqual(Searcher.PlanQty, x=>x.PlanQty)
                .CheckEqual(Searcher.PlanStatus, x=>x.PlanStatus)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProductionPlanning_View
                {
				    ID = x.ID,
                    
                    ProductionPlanning_Wo = x.Wo,
                    ProductionPlanning_Sort = x.Sort,
                    ProductionPlanning_LineId = x.LineId,
                    ProductionPlanning_LineCode = x.Line.Name,
                    ProductionPlanning_ShiftId = x.ShiftId,
                    ProductionPlanning_ShiftCode = x.Shift.Name,
                    ProductionPlanning_ProductId = x.ProductId,
                    ProductionPlanning_ProductCode = x.ProductCode,
                    ProductionPlanning_ProductName = x.Product.Name,
                    ProductionPlanning_PlanStartTime = x.PlanStartTime,
                    ProductionPlanning_PlanEndTime = x.PlanEndTime,
                    ProductionPlanning_PlanQty = x.PlanQty,
                    ProductionPlanning_PlanStatus = x.PlanStatus,
                    ProductionPlanning_CreateTime = x.CreateTime,
                    ProductionPlanning_UpdateTime = x.UpdateTime,
                    ProductionPlanning_CreateBy = x.CreateBy,
                    ProductionPlanning_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProductionPlanning_View: ProductionPlanning
    {
        
        public string ProductionPlanning_Wo { get; set; }
        public int? ProductionPlanning_Sort { get; set; }
        public long? ProductionPlanning_LineId { get; set; }
        public string ProductionPlanning_LineCode { get; set; }
        public long? ProductionPlanning_ShiftId { get; set; }
        public string ProductionPlanning_ShiftCode { get; set; }
        public long? ProductionPlanning_ProductId { get; set; }
        public string ProductionPlanning_ProductCode { get; set; }
        public string ProductionPlanning_ProductName { get; set; }
        public DateTime? ProductionPlanning_PlanStartTime { get; set; }
        public DateTime? ProductionPlanning_PlanEndTime { get; set; }
        public decimal? ProductionPlanning_PlanQty { get; set; }
        public WoStatusEnum? ProductionPlanning_PlanStatus { get; set; }
        public DateTime? ProductionPlanning_CreateTime { get; set; }
        public DateTime? ProductionPlanning_UpdateTime { get; set; }
        public string ProductionPlanning_CreateBy { get; set; }
        public string ProductionPlanning_UpdateBy { get; set; }

    }

}